/*
 * wangxiaochen only
 */
package com.naivesoft.lottery.util;

import com.naivesoft.lottery.R;

import android.app.AlertDialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * A custom dialog with a better UI
 */
public class CustomDialog extends AlertDialog {

	private Button cancelButton;
	private Button okButton;
	private TextView titleTextView;
	private TextView content;
	
	public CustomDialog(Context context) {
		super(context);
		show();
		setContentView(R.layout.util_custom_dialog);
		
		cancelButton = (Button) findViewById(R.id.button_cancel);
		okButton = (Button) findViewById(R.id.button_ok);
		titleTextView = (TextView) findViewById(R.id.dialog_title);
		content = (TextView) findViewById(R.id.dialog_content);
	}

	@Override
	public void setView(View view) {
		super.setView(view);
	}
	
	public void setCancelButton(View.OnClickListener listener) {
		setCancelButton(null, listener);
	}
	
	public void setCancelButton(String text, View.OnClickListener listener) {
		if (text != null) {
			cancelButton.setText(text);
		}
		
		if (listener != null) {
			cancelButton.setOnClickListener(listener);
		} else {
			cancelButton.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					CustomDialog.this.cancel();
				}
			});
		}
	}
	
	public void setOkButton(View.OnClickListener listener) {
		setOkButton(null, listener);
	}
	
	public void setOkButton(String text, View.OnClickListener listener) {
		if (text != null) {
			okButton.setText(text);
		}
		if (listener != null) {
			okButton.setOnClickListener(listener);
		} else {
			okButton.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					CustomDialog.this.cancel();
				}
			});
		}
	}
	
	public void setTitle(String text) {
		titleTextView.setVisibility(View.VISIBLE);
		titleTextView.setText(text);
	}
	
	public void setContent(CharSequence text) {
		content.setText(text);
	}
	
}
